package com.huanming.dsjc.modular.goods.controller;

import com.huanming.dsjc.common.controller.BaseController;
import com.huanming.dsjc.modular.goods.dao.GoodsInfoMapper;
import com.huanming.dsjc.modular.goods.entity.GoodsInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

/**
 * 原始商品管理控制器
 *
 * @author xufei
 * @Date 2018-01-31 18:53:52
 */
@Controller
@RequestMapping("/goodsinfo")
public class GoodsinfoController extends BaseController {

    private String PREFIX = "/goods/goodsinfo/";

    @Autowired
    private GoodsInfoMapper goodsinfoMapper;

    /**
     * 跳转到原始商品管理首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "goodsinfo.html";
    }

    /**
     * 跳转到添加原始商品管理
     */
    @RequestMapping("/goodsinfo_add")
    public String goodsinfoAdd() {
        return PREFIX + "goodsinfo_add.html";
    }

    /**
     * 跳转到修改原始商品管理
     */
    @RequestMapping("/goodsinfo_update/{goodsinfoId}")
    public String goodsinfoUpdate(@PathVariable Integer goodsinfoId, Model model) {
        GoodsInfo goodsinfo = goodsinfoMapper.selectById(goodsinfoId);
        model.addAttribute("goodsinfo",goodsinfo);
        return PREFIX + "goodsinfo_edit.html";
    }

    /**
     * 获取原始商品管理列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        List<GoodsInfo> list = this.goodsinfoMapper.list(condition);
        return list;
    }

    /**
     * 新增原始商品管理
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(GoodsInfo goodsinfo) {
        this.goodsinfoMapper.insert(goodsinfo);
        return super.SUCCESS_TIP;
    }

    /**
     * 删除原始商品管理
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(Integer goodsinfoId) {
        this.goodsinfoMapper.deleteById(goodsinfoId);
        return SUCCESS_TIP;
    }


    /**
     * 修改原始商品管理
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(GoodsInfo goodsinfo) {
        this.goodsinfoMapper.updateById(goodsinfo);
        return super.SUCCESS_TIP;
    }

    /**
     * 原始商品管理详情
     */
    @RequestMapping(value = "/detail")
    @ResponseBody
    public Object detail() {
        return null;
    }
}
